<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
	<title>系统设置-修改密码</title>
	<link rel="icon" href="favicon.ico" type="image/ico">
	<meta name="keywords" content="审核">
	<meta name="author" content="yinqi">
	<link href="/css/bootstrap.min.css" rel="stylesheet">
	<link href="/css/materialdesignicons.min.css" rel="stylesheet">
	<link rel="stylesheet" href="/css/index.css">
	<link rel="stylesheet" href="/js/jconfirm/jquery-confirm.min.css">
	<link href="/css/style.min.css" rel="stylesheet">

</head>
<body class="body">
<div th:insert="~{navigation :: copy}"></div>
<div class="container">
	<h2>修改密码</h2>
	<hr>
<div class="row">
	<div class="col-lg-12">
		<div class="card">
			<div class="card-body">

				<form>
					<div class="form-group">
						<label for="new-password">新密码</label>
						<input type="password" class="form-control" name="newpwd" id="new-password" placeholder="输入新的密码">
					</div>
					<div class="form-group">
						<label for="confirm-password">确认新密码</label>
						<input type="password" class="form-control" name="confirmpwd" id="confirm-password" placeholder="确认新密码">
					</div>
					<button type="button" class="btn btn-primary" onclick="editPwd()">修改密码</button>
				</form>

			</div>
		</div>
	</div>
</div>
</div>
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="/js/main.min.js"></script>
<script type="text/javascript" src="/js/axios.min.js"></script>
<script src="/js/jconfirm/jquery-confirm.min.js"></script>
<script type="text/javascript">

    function editPwd() {
        var newpwd=$('#new-password').val();
        var confirmpwd=$('#confirm-password').val();
        if(newpwd!=confirmpwd){
            console.log(newpwd);
            console.log(confirmpwd);
            $.alert({
                title: '修改密码',
                content: '请检验两次输入密码是否一致',
                buttons: {
                    confirm: {
                        text: '确认',
                        btnClass: 'btn-primary',
                    },
                    cancel: {
                        text: '取消',
                    }
                }
            });
        } else {
            axios.get('/editPwd?newpwd='+newpwd)
                .then(function (response) {
                    var data = response.data;
                    if (data == 1) {
                        $.alert({
                            title: '修改密码',
                            content: '修改成功，请重新登录',
                            buttons: {
                                confirm: {
                                    text: '确认',
                                    btnClass: 'btn-primary',
                                    action: function () {
                                        location.href = "/logout"
                                    }
                                }
                            }
                        });
                    }else {
                        $.alert({
                            title: '修改密码',
                            content: '修改失败',
                            buttons: {
                                confirm: {
                                    text: '确认',
                                    btnClass: 'btn-primary',
                                }
                            }
                        });
                    }
                })
        }
    }


</script>
</body>
</html>